"use client"; import { ConfigType } from "@/api/config"; import { GroupType } from "@/api/home"; import Box from "@/components/Box"; import { useRouter } from "@/i18n/routing"; import { Toast } from "antd-mobile"; import clsx from "clsx"; import { useTranslations } from "next-intl"; import { FC, useState } from "react"; import { Swiper, SwiperSlide } from "swiper/react"; import HomeGames from "./HomeGames"; const buttonGroup = [ { icon: "qianbao3", category_name: "sixth", isHot: false, url: "/freeGames", locale: true, lock: false, }, { icon: "qianbao3", category_name: "seventh", isHot: false, url: "/replayGames", locale: true, lock: false, }, { icon: "liwulipinjiangpin", category_name: "first", isHot: true, url: "/promo", locale: true, lock: false, }, // { // icon: "pro-youxi1", // category_name: "second", // isHot: false, // url: "/gameList/110", // locale: true, // lock: true, // }, { icon: "huodongyule", category_name: "third", isHot: false, url: "/sports", locale: true, lock: false, }, { icon: "shipin", category_name: "fourth", isHot: false, url: "/gameList/112", locale: true, lock: true, }, { icon: "yingyong", category_name: "Fifth", isHot: false, url: "/gameList/110", locale: true, lock: true, }, ] as const; type TabItemType = (typeof buttonGroup)[number] & GroupType; const TabItem = ({ item, active, onClick, }: { item: TabItemType; active?: boolean; onClick?: (item: TabItemType) => void; }) => { const t = useTranslations("ButtonGroup"); const router = useRouter(); const handler = (item: TabItemType) => { if (!item.locale) { onClick && onClick(item); return; } if (item.lock) { Toast.show("It is under development."); } else { router.push(item.url); } }; const cls = clsx("pro-iconfont text-[0.14rem]", `pro-${item.icon}`); const cls2 = clsx("iconfont text-[0.145rem]", `icon-${item.icon}`); const rootCls = clsx( "relative mr-[0.06rem] flex h-[0.3rem] bg-[#3a3a3a] flex-1 cursor-pointer items-center" + " rounded-[0.05rem] px-[0.08rem] py-[0.03rem] text-[0.12rem] text-[#fff]", { "bg-primary-color": active } ); return (
handler(item)}> {item.locale ? t(item.category_name) : item.category_name} {item.isHot && ( )}
); }; interface Props { tabs: GroupType[]; config: ConfigType; } const Tabs: FC = (props) => { const { tabs, config = { show_free_game: 2, show_again_game: 2 } } = props; const newButtonGroup = buttonGroup.filter((item: any) => { if (item.url === "/freeGames" && config.show_free_game !== 1) { return false; } if (item.url === "/replayGames" && config.show_again_game !== 1) { return false; } return true; }); const tabData = [...tabs, ...newButtonGroup]; const [active, setActive] = useState(0); const router = useRouter(); const selectHandler = (item: TabItemType, index: number) => { if (item.bet_type === 2 || item.bet_type === 3) { router.push( `/gameList/?gameListFlag=${item.category[0].jump_id}&type=1&bet_type=${item.bet_type}` ); return; } setActive(index); }; const groupGames = tabs[active]?.category; return ( <> {tabData?.map((group, index) => ( selectHandler(event, index)} > ))} ); }; export default Tabs;